const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
module.exports = {
    mode: 'development',
    entry: "./src/main.js",
    output: {
        path: path.resolve(__dirname,'dist'),
        filename: "js/bundle.js"
    },
    devServer: {    //配置webpack-dev-server
        open: true, //自动打开浏览器
        port: 8080, //配置端口
        hot: true,  //启用热更新
        contentBase: "src"
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin,  //启用热更新
        new HtmlWebpackPlugin({
            template: './src/index.html',    //指定的模板
            filename: 'index.html'
        }),
        new VueLoaderPlugin()
    ],
    module: {
        rules: [    //第三方模块的 匹配规则
            {test: /\.css$/, use: ['style-loader', 'css-loader']},
            {test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader']},
            {test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader']},
            {test: /\.(jpg|gif|png|jpeg)$/, use: 'url-loader?limit=22*1024'},
            {test: /\.js$/, use: 'babel-loader', exclude: /node-modules/},
            {test: /\.vue$/, use: 'vue-loader'},
            {test: /\.(ttf|eot|svg|woff|woff2)$/, use: 'url-loader'}
        ]
    }
}